class Solution {
public:
    //https://gitee.com/link?target=https%3A%2F%2Fleetcode.cn%2Fproblems%2F4sum%2F
    vector<vector<int>> fourSum(vector<int>& nums, int target) 
    {
        vector<vector<int>> vv1;
        sort(nums.begin(), nums.end());
        for(int i = nums.size() - 1; i > 2; i--)//依照三数之和思想，先固定一个数
        {
            for(int f = i - 1;f > 1;f--)//固定第二个数
            {
                int left = 0, right = f - 1;
                long long num = (long long)target - ( nums[i] + nums[f]);
                while(left < right)//采取双指针
                {
                    if(nums[left] + nums[right] > num) right--;
                    else if(nums[left] + nums[right] < num) left++;
                    else
                    {
                        vv1.push_back({nums[left], nums[right], nums[i], nums[f]});
                        while(left < right && nums[left] == nums[left + 1]) left++;//去重
                        while(left < right && nums[right] == nums[right - 1]) right--;
                        left++,right--;
                    }
                }
                while(1 < f && nums[f] == nums[f - 1]) f--;
            }
            while(2 < i && nums[i] == nums[i - 1]) i--;
        }
        return vv1;
    }

    //https://gitee.com/link?target=https%3A%2F%2Fleetcode.cn%2Fproblems%2Fminimum-size-subarray-sum%2F
    int minSubArrayLen(int target, vector<int>& nums) 
    {
        int left = 0, right = 0;
        int count = 0;
        int ret = nums.size() + 1;
        while(right < nums.size())//滑动窗口
        {
            count+= nums[right];
            while(count >= target)
            {
                ret = min(ret, right - left + 1);
                count -= nums[left++];//不用担心left溢出，倘若此时left==right==size-1那么count减去此下标值就不存在 >= target
            }
            right++;
        }
        return ret == nums.size() + 1? 0: ret;
    }
};